//必须带done回调 执行完成调用
import { ElMessage, ElMessageBox } from 'element-plus'
import { translateTitle } from '@/utils/i18n'

export default function confirm({ vm, action, done, eventName }) {
  // console.log('vm', vm)
  const message = action.extension.message.value
  const cancelMessage = action.extension.cancelMessage.value
  ElMessageBox.confirm(message, {
    confirmButtonText: translateTitle('Ve.utils.确认'),
    cancelButtonText: translateTitle('Ve.utils.取消'),
    type: 'warning',
  })
    .then(() => {
      done(null, {})
      // ElMessage({
      //   type: 'success',
      //   message: 'Delete completed',
      // })
    })
    .catch(() => {
      cancelMessage &&
        ElMessage({
          type: 'info',
          message: cancelMessage,
          duration: 2000,
          showClose: true,
        })
      // 修改任务队列执行状态，防止下一次事件被拦截
      vm[`${eventName}IsRunning`] = false
    })
}
